package lanou.giftsay_01.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import lanou.giftsay_01.R;
import lanou.giftsay_01.tools.GongLue;

public class llAdapter extends BaseAdapter{
    Context context ;
    ArrayList<GongLue> arrayList ;

    public void setArrayList(ArrayList<GongLue> arrayList) {
        this.arrayList = arrayList;
    }

    public llAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return arrayList != null ? arrayList.size() : 0 ;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder = null ;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_new ,parent ,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.title.setText(arrayList.get(position).getTitle());
        viewHolder.author.setText(arrayList.get(position).getName());
        Picasso.with(context).load(arrayList.get(position).getUrl()).into(viewHolder.iv);
            return convertView;
    }

    private class ViewHolder {
    TextView title ;
    TextView author ;
    ImageView iv ;

        public ViewHolder(View view) {
            title = (TextView) view.findViewById(R.id.title_new);
            author = (TextView) view.findViewById(R.id.author);
            iv = (ImageView) view.findViewById(R.id.iv_new);
        }
    }
}
